package org.jxkj.dto;

import lombok.Data;
import org.apache.commons.collections4.MapUtils;

import java.util.*;

/**
 * 读和写测点数据的结构
 * {
 * 	"data": {
 * 		"homis_AI00265": [
 * 			[
 * 				1614387600,
 * 				0
 * 			],
 * 			[
 * 				1614387601,
 * 				0
 * 			]
 * 		],
 * 		"homis_AI00266": [
 * 			[
 * 				1614387600,
 * 				0
 * 			],
 * 			[
 * 				1614387601,
 * 				0
 * 			]
 * 		]
 *        }
 * }
 */
public class PointsReqResDTO {

    private Map<String, List<List<Object>>> data;

    /**
     * 转换
     * @param map
     * @return
     */
    public static PointsReqResDTO transfer(String pointCode, Map<Integer, String> map) {
        if (MapUtils.isEmpty(map)) {
            return null;
        }

        Map<String, List<List<Object>>> data = new LinkedHashMap<>();
        map.forEach((time, value) -> {
            if (!data.containsKey(pointCode)) {
                data.put(pointCode, new ArrayList<>());
            }
            List<Object> element = new ArrayList<>(2);
            element.add(time, Double.valueOf(value));
            data.get(pointCode).add(element);
        });
        PointsReqResDTO dto = new PointsReqResDTO();
        dto.setData(data);
        return dto;
    }

    public Map<String, List<List<Object>>> getData() {
        return data;
    }

    public void setData(Map<String, List<List<Object>>> data) {
        this.data = data;
    }
}
